/**
 * @(#) ReqMedicalMoneyMediator.as
 *
 * @date		2011. 03. 28.
 * @version		1.0
 * @author		Baek, kwang hyoun
 * @description	건강보험증 신청 - Mediator
 * 				건강보험증를 신청하는 Presentation Logic을 관리
 */
package com.skt.common_hr.mompo.view
{
	import com.skt.common_hr.common.Variables;
	import com.skt.common_hr.common.approval.RequestApprovalMediator;
	import com.skt.common_hr.common.components.CommonAlert;
	import com.skt.common_hr.common.puremvc.CommonMediator;
	import com.skt.common_hr.common.utilSilver.textSilver;
	import com.skt.common_hr.mompo.HolOtOrdFacade;
	import com.skt.common_hr.mompo.model.*;
	import com.skt.common_hr.mompo.model.vo.hthIcWriteVO;
	import com.skt.common_hr.mompo.view.components.ReqHolOtOrdViewSac;
	import com.wcl.utils.DateUtil;

	import flash.events.Event;

	import mx.collections.ArrayCollection;

	import org.puremvc.as3.multicore.interfaces.INotification;

	public class ReqHolOtOrdMediator extends CommonMediator
	{
		public static const NAME:String = "ReqHolOtOrdMediator";

		public static const CLOSED_REQUEST_VIEW:String	= "closedRequestView";
 		private var bWaitingApproval:Boolean = false;
 		private var bWaitingExistData:Boolean = false;
		private var _currentKey:String = "";


		/**
		* 생성자
		*
		* @param
		* @return void
		*/
        public function ReqHolOtOrdMediator( viewComponent:Object )
        {
            super( NAME, viewComponent );
        }

		/**
		* View를 초기화 한다.
		*	- View에 기본사항을 출력하고 data를 load
		* @param
		* @return void
		*/
 		override protected function initializeView():void
 		{
 			setEventListeners();
 		}

 		private function setEventListeners():void
 		{
 			// 신청창에서 리스트창으로
// 			view.addEventListener(ReqMedicalMoneyViewSac.MedicalWriteClose, goMainList);
// 			view.addEventListener(MedicalMoneyFacade.SAVE_MEDICALMONEY_REQUEST, onSaveRequest);
 		}

 		private function removeEventListener():void
 		{
// 			view.removeEventListener(ReqMedicalMoneyViewSac.MedicalWriteClose, goMainList);
// 			view.removeEventListener(MedicalMoneyFacade.SAVE_MEDICALMONEY_REQUEST, onSaveRequest);
 		}


 		/**
		 * 입력으로 돌아가기
		 * @param
		 * @return void
		 */
 		private function goMainList(event:Event):void
 		{
 			clearView();
 			bActivated = false;
 			facade.sendNotification(CLOSED_REQUEST_VIEW, this);
 		}

 		override protected function clearView():void
 		{
 			trace("clear WriteMediator");
 		}





		///////////////////////////////////////////////////////////////////////////////////////////////////
		//
		//	Process MVC Messages
		//
		///////////////////////////////////////////////////////////////////////////////////////////////////
		/**
		* 본 Class에서 처리해야할 Noti들을 등록한다.
		*
		* @param
		* @return void
		*/
		override public function listNotificationInterests():Array
		{
			return [
//					MedicalMoneyFacade.LOAD_MEDICALMONEY_BANKA_COMPLETE,
//					MedicalMoneyFacade.LOAD_MEDICALMONEY_WRITE_INITIAL
					];
		}


		/**
		* Noti별로 처리한다.
		*
		* @param
		* @return void
		*/
		override public function handleNotification(note:INotification):void
		{
			switch(note.getName())
			{
				// 초기 로딩시..
				default:
					//trace(this.instanceID+"에서 처리 안된 Noti가 검출됨 : " + note.getBody());
					break;
			}
		}

		/**
		 * Proxy에서 DataLoad를 완료한 후 호출됨
		 *     - 조회상세보기
		 * @param
		 * @return void
		 */
 		private function setLoadedDetailInfo(voWrapObj:HolOtOrdProxy):void
 		{
// 			var vo:MedicalMoneyVO = voWrapObj.detailVO;
// 			_currentKey = vo.GWAREKEY.toString();
//
//			view.dataProvider = vo;
//			view.medicalData = voWrapObj.subTabList;
//
//			var sTargetDate:String = vo.SPMON;
//
//
//	 		loadBankInfo(Variables.myPernr);
// 			loadMedicalMoneyLimitData(Variables.myPernr, sTargetDate, vo.GWAREKEY.toString() );	//의료비 마감일자와 의료비 지원가능금액 산출
 		}

		/**
		 * MedicalMoney 저장 완료한 후 호출됨
		 *
		 * @param
		 * @return void
		 */


 		private function completeMedicalMoney(val:Object):void
 		{
 			_currentKey = val.key;


 			//AlertHelper.showMessage("임시저장이 완료되었습니다.");

/*
 			if(view.sSaveGubun == "X") {
 				//AlertHelper.showMessage("승인요청이 완료되었습니다.");
 				facade.sendNotification(ReqMedicalMoneyMediator.CLOSED_REQUEST_VIEW, this);

 			} else {
 				AlertHelper.showMessage("임시저장이 완료되었습니다.");
 			}
 */
 		}

		private function findCodeIndex(key:String, srcArr:ArrayCollection):int
		{
			for(var i:int=0; i<srcArr.length; i++) {
				if(srcArr[i].data == key) {
					return i;
				}
			}
			return -1;
		}

		//최초
		private function loadInitialData(pernr:String, name:String, gwarekey:String=""):void
		{
//			view._medicalData = new ArrayCollection();
//			_currentKey = ""; // 현재 키 초기화
//
//
// 			loadCodes();							//진료과목 코드
//
// 			if(gwarekey!="") {
// 				trace("modify data: " + gwarekey);
// 				loadExistData(gwarekey);				//의료비 신청(입력,업데이트)
// 			}
// 			else {
// 				view.writeDefaultSetting();
//
//		 		loadBankInfo(Variables.myPernr);
// 				loadMedicalMoneyLimitData(Variables.myPernr, null, "" );	//의료비 마감일자와 의료비 지원가능금액 산출
//
// 			}
		}


		///////////////////////////////////////////////////////////////////////////////////////////////////
		//
		//	Data Access Functions....
		//
		///////////////////////////////////////////////////////////////////////////////////////////////////



 		private function loadExistData(gwarekey:String):void
 		{
//			var proxy:MedicalMoneyProxy = facade.retrieveProxy(MedicalMoneyProxy.NAME) as MedicalMoneyProxy;
//			bWaitingExistData = true;
//			proxy.loadDetail(gwarekey);
 		}

 		/**
		 * 의료비 마감일자, 한도 조회
		 * @param
		 * @return void
		 */
 		private function loadMedicalMoneyLimitData(pernr:String, tagetDate:String=null, gwarekey:String=""):void
 		{
//			var proxy:ReqMedicalMoneyWriteProxy = facade.retrieveProxy(ReqMedicalMoneyWriteProxy.NAME) as ReqMedicalMoneyWriteProxy;
//			proxy.loadMmLimitData(pernr, tagetDate, gwarekey);
 		}


		///////////////////////////////////////////////////////////////////////////////////////////////////
		//
		//	Event handler (from View, Internal or....)
		//
		///////////////////////////////////////////////////////////////////////////////////////////////////

 		/**
		 * 경조사 지원기준
		 * @param
		 * @return void

 		private function displaySupportStandard(event:Event):void
 		{
 			var proxy:SupportStandardProxy = facade.retrieveProxy(SupportStandardProxy.NAME) as SupportStandardProxy;

 			var congStandardView:IFlexDisplayObject = PopUpManager.createPopUp(view, SupportStandard, true);
 			PopUpManager.centerPopUp(congStandardView);
 			(congStandardView as SupportStandard).setFocus();
 			SupportStandard(congStandardView).standardList = proxy.standardList;
 		}
 		 */
 		// 임시저장
 		private function onSaveRequest(event:Event):void
 		{
 			bWaitingApproval = false;
			commonSave();
 		}


 		private function commonSave():void {
	 		// import
			var I_GWAREKEY:String 	= _currentKey;
			var I_REQUEST:String	= "";



			// table
			//ITAB
//			var tItabArr:Array = new Array();
//			//var oItab:Object = new Object;
//			oItab.GWAREKEY	= I_GWAREKEY;
//			oItab.PERNR		= Variables.myPernr;
//			oItab.ENAME		= Variables.myName;
//
//			oItab.SPMON		= view.lbApplyDateYear.text + view.lbApplyDateMonth.text;
//			oItab.HOWMANY	= view.totalCnt;
//			oItab.HOWMUCH	= textSilver.moneyTextToInt(view.lbApplyMoney.text)/100;
//
//			//oItab.WSTATUS // 결재 진행상태
//			//oItab.WSTATX	//결재진행상태 텍스트
//
//			oItab.BANKS	= view.selectedAccount.BANKS;
//			oItab.BANKL	= view.selectedAccount.BANKL;
//			oItab.BANKA	= view.selectedAccount.BANKA;
//			oItab.BNKSA	= view.selectedAccount.BNKSA;
//			oItab.BANKN	= view.selectedAccount.BANKN;
//			oItab.EMFTX	= view.selectedAccount.EMFTX;
//			oItab.STEXT	= "";
//
//			oItab.WSTATUS= view.dataProvider.WSTATUS;
//
//			tItabArr.push(oItab);
//
//
//			// SUB_TAB
// 			var tSub_tabArr:Array = new Array();
//	 		for each(var rec:MedicalSubTabVO in view.medicalData)
//	 		{
//	 			var data:Object = new Object;
//	 			data.USEDT = DateUtil.toBasicString(rec.USEDT);
//	 			data.HOSPD = rec.HOSPD;
//	 			data.BETRG = rec.BETRG/100;
//	 			data.MEDCD = rec.MEDCD;
//	 			data.MEDTX = rec.MEDTX
//
//	 			tSub_tabArr.push(data);
//	 		}
//
// 			var proxy:MedicalMoneyProxy = facade.retrieveProxy(MedicalMoneyProxy.NAME) as MedicalMoneyProxy;
// 			proxy.save(I_GWAREKEY, I_REQUEST, tItabArr, tSub_tabArr);
 		}

 		/**
		 * 경조사 저장수정
		 * @param
		 * @return void
		 */
		 /*
 		private function onCongMoneyWriteUpdate(event:CongMoneyWriteEvent):void
 		{
 			//facade.removeMediator(CongMoneyWriteMediator.NAME);
 			var proxy:CongMoneyWriteProxy = facade.retrieveProxy(CongMoneyWriteProxy.NAME) as CongMoneyWriteProxy;
 			proxy.update(event.Fkey, event.writeVo);
 		}
 		 */
 		/**
		 * 경조사 입력팝업닫기
		 * @param
		 * @return void
		 */
 		private function onCongClose(event:Event):void
 		{
 			clearView();
 			bActivated = false;
 			facade.sendNotification(CLOSED_REQUEST_VIEW, this);
 		}

 		 //의료비 상세보기 조회
 		private function onSelected(proxy:HolOtOrdProxy):void
 		{
 			//var congProxy:ReqMedicalMoneyWriteProxy = facade.retrieveProxy(ReqMedicalMoneyWriteProxy.NAME) as ReqMedicalMoneyWriteProxy;
			//congProxy.load(proxy.key);

 			//corsnLoadData();
 			//bankaLoadData();
 		}


	}
}